home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / rdflib / syntax / xml_names.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.5 KB  |  65 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from unicodedata import category, decomposition
  5. NAME_START_CATEGORIES = [
  6.     'Ll',
  7.     'Lu',
  8.     'Lo',
  9.     'Lt',
  10.     'Nl']
  11. NAME_CATEGORIES = NAME_START_CATEGORIES + [
  12.     'Mc',
  13.     'Me',
  14.     'Mn',
  15.     'Lm',
  16.     'Nd']
  17. ALLOWED_NAME_CHARS = [
  18.     u'¬∑',
  19.     u'Œá',
  20.     u'-',
  21.     u'.',
  22.     u'_']
  23.  
  24. def is_ncname(name):
  25.     first = name[0]
  26.     if first == '_' or category(first) in NAME_START_CATEGORIES:
  27.         for i in xrange(1, len(name)):
  28.             c = name[i]
  29.             if category(c) not in NAME_CATEGORIES:
  30.                 if c in ALLOWED_NAME_CHARS:
  31.                     continue
  32.                 
  33.                 return 0
  34.         
  35.         return 1
  36.     return 0
  37.  
  38. XMLNS = 'http://www.w3.org/XML/1998/namespace'
  39.  
  40. def split_uri(uri):
  41.     if uri.startswith(XMLNS):
  42.         return (XMLNS, uri.split(XMLNS)[1])
  43.     length = len(uri)
  44.     for i in xrange(0, length):
  45.         c = uri[-i - 1]
  46.         if category(c) not in NAME_CATEGORIES:
  47.             if c in ALLOWED_NAME_CHARS:
  48.                 continue
  49.             
  50.             for j in xrange(-1 - i, length):
  51.                 if category(uri[j]) in NAME_START_CATEGORIES or uri[j] == '_':
  52.                     ns = uri[:j]
  53.                     if not ns:
  54.                         break
  55.                     
  56.                     ln = uri[j:]
  57.                     return (ns, ln)
  58.             
  59.             break
  60.             continue
  61.         uri[j] == '_'
  62.     
  63.     raise Exception("Can't split '%s'" % uri)
  64.  
  65.